package com.example.apprank.common.domain;

import com.example.apprank.common.enums.ResultCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@NoArgsConstructor
public class Result<T> {
    public static <T> Result<T> success(T data) {
        return assembleResult(data,
                ResultCode.SUCCESS);
    }
    public static <T> Result<T> success() {
        return assembleResult(
                null,ResultCode.SUCCESS);
    }
    public static <T> Result<T> failed() {
        return assembleResult(null,ResultCode.FAILED);
    }
    public static <T> Result<T> failed(int code,String message) {
        return assembleResult(message,code,null);
    }
    public static <T> Result<T> failed(String message,int code) {
        return assembleResult(message,code,null);
    }
    public static <T> Result<T> failed(ResultCode resultCode) {
        return assembleResult(null, resultCode);
    }
    public static <T> Result<T> assembleResult( String msg,int code,T data) {
        Result<T> result=new Result<>();
        result.setCode(code);
        result.setMessage(msg);
        result.setData(data);
        return result;
    }
    public static <T> Result<T> assembleResult(T data,ResultCode resultCode) {
        Result<T> result=new Result<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMsg());
        result.setData(data);
        return result;
    }
    public int code;
    public String message;
    public  T data;

    public void setCode(int code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }
}
